/**
 * 分页对象核心js
 * @wu.i
 */
var qryPager;
(function(scope) {
	var PageTpl = Base.extend({
		constructor : function(attribute) {
			attribute= attribute || {};
			this.set_attr(attribute);
			this.def_page_size =10;
			this.param = {"page_size":attribute['page_size'] || this.def_page_size}
		},
		set_attr:function(attribute){
			attribute= attribute || {};
			this.tplLi = attribute.clone_elt|| "comment_li_tpl";
			
			this.tplUlId = attribute.clone_scope || "ul_lists";
			this.page_nav =attribute.page_nav || 'pageNav';
			this.clone_elt_type=attribute.clone_elt_type || "li";
			this.qry_scope_id =attribute['qry_scope_id'] || '';
		},
		getParam :function(){ //获取参数
			var p_param =commonJS.getInputDomain(this.qry_scope_id); //组装参数
			jQuery.extend(this.param,p_param);
			return this.param;
		},
		setParam : function(currJq,json_data) {
			jQuery.extend(this.param, json_data);
		},
		query_info : function() {
			
			var param = this.getParam(), me = this;
			if (!qryPager) {
				var pager = new Pager(this.page_nav,this.param["service_name"],this.param.method, false, [param],
						function(reply) {
							me.render_info(reply);
						}, false, false, false, null, 'simple', false);
				window.qryPager = pager;
			} else {
				window.qryPager.setParam(param);
				param.page_index = 1;
				window.qryPager.doService(param);
			}
		},
		render_info : function(reply) {
			var me = this;
			if(typeof(this.render_info_before) =="function")
				this.render_info_before();
		
			if (reply)
			{
				this.gettplUl().children(this.clone_elt_type+":gt(0)").remove();
				for (var i = 0, liData; liData = reply.list[i++];) {
					this.bind_event(liData);
				}
			} else 
			{
				this.gettplUl().children(this.clone_elt_type+":gt(0)").fadeIn("fast",function() {me.gettplUl().children("li:gt(0)").remove();})
			}
		},
		bind_event : function(jsonData) {
			var cloneLi = this.gettplLi().clone(), me = this;
			cloneLi.data("qry_data", jsonData || {});
			(function(cloneLi) {
				var qry_data = cloneLi.data("qry_data");
				me.gettplUl().append(cloneLi.attr("id", "").show());
				me.record_event(qry_data,cloneLi);
				
			}(cloneLi));
		},
		record_event:function(qry_data,cloneLi){},////TODO 子类实现}
		gettplUl:function(){
			return $("#"+this.tplUlId);
		},
		gettplLi:function(){
			return $("#"+this.tplLi);
		},
		resetValues:function(){//重置所有值
			$("[fieldType='db'][type!='radio']").val("");
		},
		setDisabled:function(type){//设置为不可编辑
			if(type=="0"){
				$("[fieldType='db']").attr("disabled",true);
			}
			else
				$("[fieldType='db']").removeAttr("disabled");
		}
	})
	window.PageTpl =PageTpl;
}(window));

